<?php
	/**
	 * @package AmpleHarvest
	 */
	use\ampleharvest\code;

	/**
	 * @brief This file is used to Run all notifications that are due.
	 *
	 * - Revision History
	 *  - 0.1
	 * 	 - <b>Date</b>: 24 MAR 2011
	 * 	 - <b>Author</b>: Randy Blancett
	 * 	  - Initial Version
	 *
	 * @author Randy Blancett
	 * @version 0.1
	 * @ingroup code script classes
	 */
	require_once dirname(dirname(dirname(__FILE__))) . '/config/cConfig.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/cStomp.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/cAmpleHarvestLog.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/notification/cMailNotification.php';

	$obj_Log = new \cAmpleHarvestLog();
	$obj_Stomp = new \cStomp();
	$obj_Email = new \cMailNotification();

	$obj_Stomp->subscribe(\cStomp::C_STR_QUEUE_EMAIL);

	$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_EMAIL_INFO,
		"Started Sending Emails",
		cAmpleHarvestLog::C_INT_LEVEL_INFO);

	while ($obj_Msg = $obj_Stomp->getMessage())
	{
		$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_EMAIL_INFO,
			"Pulled Email from Queue",
			cAmpleHarvestLog::C_INT_LEVEL_DEBUG);

		//print_r($obj_Msg);

		$bool_Return = $obj_Email->send_JSONMail($obj_Msg->body);

		if ($bool_Return)
		{
			print("Email Sent");
		}
		else
		{
			print("Email Not Sent");
		}

		$obj_Stomp->ackMessage($obj_Msg);
	}
	print("Finish\n");

	$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_EMAIL_INFO,
		"Finished Sending Emails",
		cAmpleHarvestLog::C_INT_LEVEL_INFO);

?>
	